// 导入request请求工具
import request from '@/utils/request'

// 获取所有订单
export const orderListService = (params) => {
  return request({
    url: '/order/list',
    method: 'get',
    params: { pageNum: params.pageNum, pageSize: params.pageSize }
  })
}

//下架
export function takeDown(params) {
  return request({
    method: 'put',
    url: 'order/takeDownOrder/' + params.item,
  })
}
//上架
export function takeUp(params) {
  return request({
    method: 'put',
    url: 'order/takeUpOrder/' + params.item,

  })
}

// 添加订单
export function addOrder(params) {
  return request({
    method: 'post',
    url: 'order',
    data: params,

  })
}

// 分页查询所有货源（商品）订单
export function selectGoodsPage(params) {
  if (params.keys == "") {
    return request({
      method: 'get',
      url: 'order/goods/' + params.pageNum,
      // params: params,
    })
  } else {
    return request({
      method: 'get',
      url: 'order/searchGoodsByKeys/' + params.keys + '/' + params.pageNum,
      // params: params,

    })
  }
}
// 分页条件查询所有货源（商品）订单
export function searchAlIByCondition(params) {
  // 确保params对象包含pageNum和pageSize，以及OrderConditionDTO的所有属性
  const pageNum = params.pageNum || 1;
  const pageSize = params.pageSize || 10;
  return request({
    method: 'get',
    url: '/order/searchAlIByCondition',
    params: {
      pageNum: pageNum,
      pageSize: pageSize,
      type: params.type || null,
      content: params.content || null,
      ownName: params.ownName || null
    }
  });
}



// 分页查询所有需求订单
export function selectNeedsPage(params) {
  return request({
    method: 'get',
    url: 'order/findByNeeds',
    params: params,
  })
}

//根据id查询订单
export function selectOrderById(params) {
  return request({
    method: 'get',
    url: 'order/' + params.id,

  })
}

//根据id修改订单
export function updateOrderById(params) {
  return request({
    method: 'put',
    url: 'order/' + params.order_id,
    data: params,

  })
}

// 根据id删除订单
export function deleteOrderById(params) {
  return request({
    method: 'delete',
    url: 'order/' + params.order_id,
    params: params,

  })
}

//根据用户名+订单类型查询订单
export function selectOrderByUsernameAndType(params) {
  if (params.ctype == 'goods' && params.keys !== '') {
    return request({
      method: 'get',
      url: `/order/searchMyGoodsByKeys/${params.keys}/${params.pageNum}`,

    })
  } else if (params.ctype == 'needs' && params.keys !== '') {
    return request({
      method: 'get',
      url: `/order/searchMyNeedsByKeys/${params.keys}/${params.pageNum}`,

    })
  } else {
    return request({
      method: 'get',
      url: 'order/search/' + params.ctype + '/' + params.pageNum,

    })
  }
}

// //根据种类，用户名查询个人商品模糊查询
// export function selectOrderByKeys(params) {
//     return request({
//         method: 'get',
//         url: 'order/search/' + params.ctype + '/' + params.pageNum,
//         headers: {
//             'Authorization': window.localStorage.token,
//         },
//     })
// }

// 根据登陆用户查询我买的订单
export function selectBuyByUserName(params) {
  return request({
    method: 'get',
    url: 'order/selectBuys',

  })
}

// 根据登陆用户查询我买的订单
export function selectOwnByName(params) {
  return request({
    method: 'get',
    url: 'user/' + params.own_name,

  })
}

// 根据登录用户查询我卖的订单
export function selectSellByUserName(params) {
  return request({
    method: 'get',
    url: 'order/selectSells',

  })
}

// 问答详情
export function questionDetail(params) {
  return request({
    method: 'get',
    url: `/question/selectById//${params.id}`,

  })
}
//去提问
export function addQuestion(params) {
  return request({
    method: 'post',
    url: `/question/add`,
    data: params
  })
}

//去预约
export function addReserve(params) {
  return request({
    method: 'post',
    url: `/reserve/add`,
    data: params
  })
}

